package com.wonders.framework.auto.builder.code.convert.instance;

import com.wonders.framework.auto.builder.code.convert.BaseTagConvert;
import com.wonders.framework.auto.builder.code.entity.vo.BuildColumn;
import com.wonders.framework.auto.builder.code.entity.vo.BuildTable;

/**
 * 实体toString标签转换器
 * 
 * @author WuBin
 * 
 */
public class EntityToStringConvert extends BaseTagConvert {

	@Override
	public String convert(String str, String tag, BuildTable buildTable) {
		String prefix = super.getPrefix(str, tag);
		str = prefix + "public String toString() {";
		str += "\n";
		str += prefix + "  return \"" + buildTable.getClassName()
				+ ("#vo-toString#".equals(tag) ? "Vo" : "") + " [";
		for (int i = 0; i < buildTable.getColumns().size(); i++) {
			BuildColumn buildColumn = buildTable.getColumns().get(i);
			if (i > 0) {
				str += ", ";
			}
			str += buildColumn.getPropertyName() + "=\" + "
					+ buildColumn.getPropertyName() + " + \"";
		}
		str += "]\";";
		str += "\n";
		str += prefix + "}";
		str += "\n";
		return str;
	}

}
